using System.Linq;
using HQLAddin.Highlighting.Classificators;
using Microsoft.VisualStudio.Text.Classification;
using Moq;
using NUnit.Framework;
using SharpTestsEx;

namespace HQLAddin.Tests.Highlighting
{
	public class ParameterClassifierTest
	{
		[Test]
		public void ShouldWorkForNumberParameters()
		{
			var parameterClassifier = new ParameterClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			var regex = parameterClassifier.Regexs.First();
			var matches = regex.Matches("from :1");
			matches.Satisfy(m => m.Count == 0);
		}

		[Test]
		public void WhenParameterStarWithNumberThenDontMatch()
		{
			var parameterClassifier = new ParameterClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			var regex = parameterClassifier.Regexs.First();
			var matches = regex.Matches("where a.id = :1 or b.id = :2");
			matches.Satisfy(m => m.Count == 0);
		}

		[Test]
		public void WhenParameterIsPOsitionalThenMatch()
		{
			var parameterClassifier = new ParameterClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			var regex = parameterClassifier.Regexs.Last();
			var matches = regex.Matches("where a.id = ?");
			matches.Satisfy(m => m.Count == 1 && m[0].Value == "?" && m[0].Index == 13);
		}

		[Test]
		public void ShouldWorkForNamedParameters()
		{
			var parameterClassifier = new ParameterClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			var regex = parameterClassifier.Regexs.First();
			var matches = regex.Matches("where a.id = :par1 or b.id = :par");
			matches.Satisfy(m => m.Count == 2 && m[0].Value == ":par1" && m[1].Value == ":par");
		}

		[Test]
		public void ShouldWorkForOneCharParameters()
		{
			var parameterClassifier = new ParameterClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			var regex = parameterClassifier.Regexs.First();
			var matches = regex.Matches("where a.id = :p");
			matches.Satisfy(m => m.Count == 1 && m[0].Value == ":p");
		}
	}
}